//
//  MHUserModel.m
//  M-Saler
//
//  Created by Teresa on 2020/5/25.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "MHUserModel.h"
#import "MHLoginRequest.h"

#define UserModelKey @"UserModelKey"

@implementation MHUserModel
MJCodingImplementation

+ (MHUserModel *)userModel{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults synchronize];
    NSDictionary *dict = [userDefaults objectForKey:UserModelKey];
    if(dict){
        MHUserModel *userModel = [MHUserModel objectWithDictionaryRepresentation:dict];
        return userModel;
    }
    return nil;
}

-(BOOL)didLogin{
    if (self.authentication.length > 1) {
        return YES;
    }
    return NO;
}

- (void)save{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:[self getJsonDictionary] forKey:UserModelKey];
    [userDefaults synchronize];
}


+ (void)logout{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:UserModelKey];
    [userDefaults synchronize];
}

+ (void)syncUserInfo{
    MHLoginRequest *req = [MHLoginRequest new];
    req.hideLoadingView = YES;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        
    } failHandler:^(BaseResponse *response) {
        
    }];
}

+(NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"uid":@"id"};
}


@end
